﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Data.Linq.Mapping;
using System.Data.Linq;
using System.Data;
using System.Collections.Generic;
using System.Reflection;
using System.Linq.Expressions;

namespace lINQtoSQL
{
    class EmployeeNew:Employee
    {
        private EntitySet<Territory> terrritories;

        public EmployeeNew(EntitySet<Territory> terrritories)
        {
            this.terrritories = terrritories;
        }

        public EntitySet<Territory> Terrritories
        {
            get
            {
                System.Linq.IQueryable<Territory> territoriesList;
                DataClassesNorthwindDataContext context = new DataClassesNorthwindDataContext();
                using (context)
                {
                    territoriesList =
                        (from c in context.Employees
                        join
                            et in context.EmployeeTerritories on c.EmployeeID equals et.EmployeeID
                        join
                            t in context.Territories on et.TerritoryID equals t.TerritoryID
                            where et.EmployeeID==this.EmployeeID
                        select t);

                }
                EntitySet<Territory> ent = new EntitySet<Territory>(); 
                foreach (var item in territoriesList)
                {
                    ent.Add(item);
                }
                return ent;
            }
            set
            {
                terrritories = value;
            }
        }




    }
}
